﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JetRetail
{
    public partial class ЗакрытиеЧекаСКомбинированнойОплатойForm : Form
    {
        decimal deКОплате;

        public decimal deCash, deCard, deChange;

        public ЗакрытиеЧекаСКомбинированнойОплатойForm(decimal deКОплате)
        {
            this.deКОплате = deКОплате;

            InitializeComponent();
        }

        private void Cash_TextChanged(object sender, EventArgs e)
        {
            bool boOK = false;

            try
            {
                deCash = (Cash.Text.Length == 0) ? (0) : (decimal.Parse(Cash.Text));
                deCard = (Card.Text.Length == 0) ? (0) : (decimal.Parse(Card.Text));
                deChange = deCash + deCard - deКОплате;
                if (deChange >= 0)
                {
                    Change.Text = "" + (int)deChange;
                    boOK = true;
                }
                else Change.Text = "";
            }
            catch (Exception)
            {
                Change.Text = "";
                boOK = false;
            }

            OK.Enabled = boOK;
        }

        private void Card_TextChanged(object sender, EventArgs e)
        {
            bool boOK = false;

            try
            {
                deCash = (Cash.Text.Length == 0) ? (0) : (decimal.Parse(Cash.Text));
                deCard = (Card.Text.Length == 0) ? (0) : (decimal.Parse(Card.Text));
                deChange = deCash + deCard - deКОплате;
                if (deChange >= 0)
                {
                    Change.Text = "" + (int)deChange;
                    boOK = true;
                }
                else Change.Text = "";
            }
            catch (Exception)
            {
                Change.Text = "";
                boOK = false;
            }

            OK.Enabled = boOK;
        }

        private void OK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            Close();
        }
    }
}